package com.example.bootdemo.service.impl;

import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.example.bootdemo.common.util.ExcelStyleUtil;
import com.example.bootdemo.common.util.IntegerChangeString;
import com.example.bootdemo.dao.EmployeeMapper;
import com.example.bootdemo.entity.Employee;
import com.example.bootdemo.service.EmployeeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Resource
    private EmployeeMapper employeeMapper;

    /**
     * 员工档案信息的导出
     *
     * @return
     */
    @Override
    public Map findEmployeeEntryForRecord(Map infoMap) {
        //数据
        //dto
        // 员工入职基本信息
//        List<EmployeeEntryDto> employeeEntryDtos =
        List<Employee> employees = employeeMapper.listEmployeeByChoose(infoMap);

        //标题列
        List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>();

        //向标题列中 放 基本列
        ExcelExportEntity colEntity = new ExcelExportEntity("序号", "sort");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("工号", "jobNumber");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("姓名", "name");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("性别", "sex");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("部门", "department");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("职位", "job");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("工作地点", "workPlace");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("入职时间", "inTime");
        colEntity.setNeedMerge(true);
        ExcelStyleUtil.dateFormat(colEntity);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("转正时间", "endProbationTime");
        colEntity.setNeedMerge(true);
        ExcelStyleUtil.dateFormat(colEntity);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("入职前工作年限", "workYear");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("招聘HR", "hrName");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        colEntity = new ExcelExportEntity("状态", "employeeStatus");
        colEntity.setNeedMerge(true);
        colList.add(colEntity);
        //dto 转 map  向Excel内循环 添加数据
        //总数据
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Integer employeeStatus = null;
        String excelEmpStaus = "";
        for (int i = 0; i < employees.size(); i++) {
            employeeStatus = employees.get(i).getEmployeeStatus();
            //员工状态 转文字
            excelEmpStaus = IntegerChangeString.setEmployeeStatus(employeeStatus);
            //基本列数据
            Map<String, Object> valMap = new HashMap<String, Object>();
            valMap.put("sort", (i + 1));
            valMap.put("jobNumber", employees.get(i).getJobNumber());
            valMap.put("name", employees.get(i).getName());
            valMap.put("sex", employees.get(i).getSex());
            valMap.put("department", employees.get(i).getDepartment());
            valMap.put("job", employees.get(i).getJob());
            valMap.put("workPlace", employees.get(i).getWorkPlace());
            valMap.put("inTime", employees.get(i).getInTime());
            valMap.put("endProbationTime", employees.get(i).getEndProbationTime());
            valMap.put("employeeStatus", excelEmpStaus);
            valMap.put("workYear", employees.get(i).getWorkYear());
            valMap.put("hrName", employees.get(i).getHrName());
            list.add(valMap);
        }
        Map map = new HashMap();
        ExportParams exportParams = new ExportParams("员工档案信息表（HR用）", "基本信息");
        exportParams.setStyle(ExcelStyleUtil.class);
        map.put("title", exportParams);
        map.put("entity", colList);
        map.put("data", list);
        return map;
    }
}
